<template>
	<view>
		<view class="uni-padding-wrap uni-common-mt">
			<view class="uni-flex uni-column">
				<view class="uni-title">请输入内容</view>

				<view class="uni-textarea">
					<textarea v-model="content" auto-height placeholder="最多 255 个字符" />
				</view>

				<view class="height-50" v-for="cnt in 3"></view>

				<view class="uni-flex uni-row">
					<button @click="cancel" class="btn-cancel" type="default">返回</button>
					<button @click="submit" class="btn-submit" type="primary">提交</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content: ''
			}
		},
		onLoad: function(e) {
			// console.log(typeof this.$myRequest);
			// console.log(e);
		},
		methods: {
			submit: function(e) {
				// verify data
				if (this.content == '') {
					uni.showToast({
						icon: 'error',
						title: '内容不能为空！'
					});
					return;
				}
				
				if (this.content.length > 255) {
					uni.showToast({
						icon: 'error',
						title: '长度不能大于 255'
					});
					return;
				}
				
				uni.showModal({
					content: '确定增加分数吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '正在增加分数',
								mask: true
							});
							
							const add = this.$request({
								url: this.$api.add,
								method: 'POST',
								data: {
									type: 0,
									content: this.content
								}
							})
							.then((res) => {
								console.log(res.data);
								setTimeout(function () {
								    uni.hideLoading();
								    uni.navigateBack();
								}, 1000);
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
							uni.showToast({
								icon: 'none',
								title: '取消'
							});
						}
					}
				});
			},

			cancel: function(e) {
				uni.navigateBack();
			}
		}
	}
</script>

<style>
	.height-50 {
		height: 50rpx;
	}
	
	.btn-submit {
		/* padding: 300rpx; */
	}

	.btn-submit,
	.btn-cancel {
		-webkit-flex: 1;
		flex: 1;
		margin: 50rpx;
	}
</style>
